/**
 * 
 */
window.wangEditor.extend = {
	// editor create之后调用
	init: function(editorSelector){
		var fullHtml= '<div class="w-e-menu right-ele" title="全屏"><a class="_wangEditor_btn_fullscreen img-fullScreen" href="###" onclick="window.wangEditor.extend.toggleFullscreen(\'' + editorSelector + '\')"></a></div>';
		var previewHtml = '<div class="w-e-menu" title="预览"><a class="_wangEditor_btn_fullscreen img-preview" href="###" onclick="window.wangEditor.extend.preview(\'' + editorSelector + '\')"></a></div>';
		$(editorSelector + " .w-e-toolbar").append(previewHtml).append(fullHtml);
	},
	/*全屏切换*/
	toggleFullscreen: function(editorSelector){
		window.wangEditor.extend.__ispopup(editorSelector);
		$(editorSelector).toggleClass('fullscreen-editor');
		if($(editorSelector + ' ._wangEditor_btn_fullscreen').hasClass('hover')){
			$(editorSelector + ' ._wangEditor_btn_fullscreen').removeClass('hover')
				.attr('title','全屏');
		}else{
			$(editorSelector + ' ._wangEditor_btn_fullscreen').addClass('hover')
				.attr('title','退出全屏');
		}
	},
	/*预览*/
	preview:function (editorSelector) {
		var html = $(editorSelector).find('.w-e-text-container .w-e-text').html();
		var fullHtml = '<div class="full-preview">' +
				'<div class="w-e-toolbar" style="background-color:#f1f1f1; border:1px solid #ccc;height:36px;">预览' +
					'<div class="w-e-menu right-ele w-e-icon-close" onclick="window.wangEditor.extend.closePreview(\'' + editorSelector + '\')"></div>' +
				'</div>' +
				'<div class="w-e-text-container">' +
					'<div class="w-e-text">' +
					html+
					'</div>'+
				'</div>'+
			'</div>';
		/*特殊标记替换*/
		var reg = /classex="plain"|classex="c\+\+"|classex="c#"|classex="java"|classex="js"|classex="php"|classex="python"|classex="sql"/g;  //  找到北京 或者天安门 全局匹配
		var result = fullHtml.replace(reg,function (res) {
			var result = res.replace(/classex="/g,'');
			return 'class="brush:'+result;
		});
		
		$('body').append(result);
		SyntaxHighlighter.all();
	},
	/*关闭预览*/
	closePreview:function (editorSelector) {
		$('.full-preview').remove();
	},
	/*弹出层时特殊处理*/
	__ispopup:function (editorSelector) {
		var $pop = $('#answer_pop');
		if($pop.length>0 && $pop.css('display')!='none'){
			if($(editorSelector + ' ._wangEditor_btn_fullscreen').hasClass('hover')){
				return;
			}else{
				if(!$pop.children('.pop-answer').hasClass('is-full-screen')){
					$pop.children('.pop-answer').addClass('is-full-screen');
				}
			}
		}
	}
};